#include "Wezel.h"
#include "Element.h"

Wezel::Wezel(unsigned id): _id(id), _v(0) { };
void Wezel::wyswietl(Wyjscie& wy)
{
	wy << "V" << _id << ", liczba elementow: " << liczbaElementow() << "\n";
	for(unsigned i = 0; i < _tabR.size(); i++)
		wy << "\tR" << _tabR[i] -> Id() << " = " << _tabR[i] -> r() << " Ohm | V1: " << _tabR[i] -> v1()->id() << " V2: " << _tabR[i] -> v2()->id()  << "\n";
	for(unsigned i = 0; i < _tabE.size(); i++)
		wy << "\tE" << _tabE[i] -> Id() << " = " << _tabE[i] -> u() << " V, " << _tabE[i] -> r() << " Ohm | V1: " << _tabE[i] -> v1() ->id() << " V2: " << _tabE[i] -> v2()->id()  << "\n";
	for(unsigned i = 0; i < _tabI.size(); i++)
		wy << "\tI" << _tabI[i] -> Id() << " = " << _tabI[i] -> i() << " A | V1: " << _tabI[i] -> v1() ->id() << " V2: " << _tabI[i] -> v2()->id()  << "\n";
}
double Wezel::sumaKonduktancji()
{
	double sk = 0;
	for(unsigned i = 0; i < _tabR.size(); i++)
		sk += _tabR[i] -> konduktancja();
	return sk;
}
double Wezel::sumaWymuszen()
{
	double sw = 0;
	for(unsigned i = 0; i < _tabI.size(); i++)
	{
		if(this == _tabI[i] -> v1())
			sw -= _tabI[i] -> i();
		if(this == _tabI[i] -> v2())
			sw += _tabI[i] -> i();
	}
	for(unsigned i = 0; i < _tabE.size(); i++)
	{
		if(_tabE[i]->v2() == this)
			sw += _tabE[i] -> u() / _tabE[i] -> r();
		if(_tabE[i]->v1() == this)
			sw -= _tabE[i] -> u() / _tabE[i] -> r();
	}

	return sw;
}
int Wezel::liczbaElementow()
{
	return _tabR.size() + _tabE.size() + _tabI.size();
}